package view.micro.background
{
	import flash.display.Sprite;
	import util.Random;
	import util.Settings;
	import view.micro.IMicroSprite;
	
	/**
	 * A cloud sprite for the background of battles.
	 */
	public class CloudSprite extends Sprite implements IMicroSprite
	{
		private var xspeed:Number;
		
		/**
		 * Create a new cloud.
		 */
		public function CloudSprite()
		{
			x = Random.integer(10, 500);
			y = Random.integer(200, 380);
			xspeed = Random.uniform(Settings.METER, Settings.METER * 3.0);
			makeSprite();
		}
		
		/**
		 * Create the graphics.
		 */
		private function makeSprite():void
		{
			graphics.clear();
			for (var i:int = Random.integer(14, 18); i > 0; i--)
			{
				graphics.beginFill(0xFFFFFF, Random.uniform(0.2, 1));
				graphics.drawCircle(Random.integer(-25, 25), Random.integer(-15, 15), Random.integer(5, 18));
				graphics.endFill();
			}
		}
		
		/**
		 * Called every frame.
		 */
		public function update():void
		{
			x += xspeed * Settings.getTimeStep();
			
			if (x > stage.stageWidth + width)
			{
				makeSprite();
				x = -width;
				y = Random.integer(200, 380);
			}
		}
		
		public function readyToRemove():Boolean
		{
			return false;
		}
	
	}

}